switch and define


Tip
The instruction switch is typically used with an integer value. It is a good programming technique to use the pre-processor instruction define to make the code more readable as shown in the program below.
La instrucción switch es típicamente usada con un valor entero. Una técnica de la buena programación sugiere usar la instrucción define del pre-procesador para hacer el código más fácil de leer como se muestra en el programa de abajo.

Program.h
#pragma once
#include "resource.h"
#define SUNDAY 0
#define MONDAY 1
#define TUESDAY 2
#define WEDNESDAY 3
#define THURSDAY 4
#define FRIDAY 5
#define SATURDAY 6
class Programa : public Win::Dialog
{
public:
     Programa()
{
     ...
};

Program.cpp
void Programa::Window_Open(Win::Event& e)
{
     const int day = FRIDAY;
     switch(day)
     {
     case MONDAY:
     case TUESDAY:
          this->MessageBox(L"Cansado", L"Tired", MB_OK);
          break;
     case WEDNESDAY:
     case THURSDAY:
          this->MessageBox(L"Casi llega", L"Almost there", MB_OK);
          break;
     default:
          this->MessageBox(L"Relajate", L"Relax", MB_OK);
     }
}

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home